<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link href="/public/tree/bootstrap.css" rel="stylesheet">
    <link href="/public/tree/bootstrap-responsive.css" rel="stylesheet">
    <link href="/public/tree/base.css" rel="stylesheet">
    <link href="/public/tree/sweet-alert.css" rel="stylesheet">
    <script src="/public/tree/jquery.js"></script>
    <script src="/public/tree/bootstrap.min.js"></script>
    <script src="/public/tree/sweet-alert.min.js"></script>
    <title>计划任务系统</title>
</head>
<body style="padding:10px;">

<div style="width:460px;margin:auto;padding-top:200px;">
    <div class="well">
        <form class="form-horizontal" onsubmit="return login();">
            <legend>计划任务系统</legend>
            <div class="control-group">
                <label class="control-label">帐号</label>
                <div class="controls">
                    <input type="text" id="username" name="username" placeholder="后台管理账号">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="Password">密码</label>
                <div class="controls">
                    <input type="password" id="password" name="password" placeholder="后台管理密码">
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <button type="submit" class="btn">登录</button>
                </div>
            </div>
            <div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">

    function login() {
        var username = $('#username').val();
        var password = $('#password').val();

        if(! username) {
            swal({   title: "请输入用户名",timer: 2000 });
            return false;
        }

        if(! password) {
            swal({   title: "请输入密码",timer: 2000 });
            return false;
        }

        $.ajax({
            type: "POST",
            url: "/login/ajax",
            data: {user:username, pwd: password},
            async: true,
            success: function(json) {
                if(json.code == -1) {
                    swal({   title: json.data,timer: 2000 });
                } else if (json.code == 1) {
                    window.location = '/';
                }
            },
            dataType: "json"
        });

        return false;
    }
</script>
</body>
</html>
